package cn.zhpdmmz.service.impl;

import cn.zhpdmmz.entity.HotelRoomType;
import cn.zhpdmmz.mapper.HotelRoomTypeMapper;
import cn.zhpdmmz.service.IHotelRoomTypeService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (HotelRoomType)表服务实现类
 *
 * @author CJW
 * @since 2022-03-16 21:32:59
 */
@Service("hotelRoomTypeService")
public class HotelRoomTypeServiceImpl implements IHotelRoomTypeService {
    @Resource
    private HotelRoomTypeMapper hotelRoomTypeMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param roomTypeId 主键
     * @return 实例对象
     */
    @Override
    public HotelRoomType queryById(Integer roomTypeId) {
        return this.hotelRoomTypeMapper.queryById(roomTypeId);
    }

    /**
     * 查询指定行
     *
     * @param hotelRoomType 筛选条件
     * @return 查询结果
     */
    @Override
    public List<HotelRoomType> queryAll(HotelRoomType hotelRoomType) {
        return this.hotelRoomTypeMapper.queryAll(hotelRoomType);
    }

    /**
     * 新增数据
     *
     * @param hotelRoomType 实例对象
     * @return 实例对象
     */
    @Override
    public HotelRoomType insert(HotelRoomType hotelRoomType) {
        List<HotelRoomType> hotelRoomTypeList = this.hotelRoomTypeMapper.queryTheAll();
        for(int i = 0; i < hotelRoomTypeList.size(); i++){                     //判断房间类型是否有重复
            if(hotelRoomTypeList.get(i).getRoomGrade().equals(hotelRoomType.getRoomGrade())){
                return null;
            }
        }
        this.hotelRoomTypeMapper.insert(hotelRoomType);
        return hotelRoomType;
    }

    /**
     * 修改数据
     *
     * @param hotelRoomType 实例对象
     * @return 实例对象
     */
    @Override
    public HotelRoomType update(HotelRoomType hotelRoomType) {
        this.hotelRoomTypeMapper.update(hotelRoomType);
        return this.queryById(hotelRoomType.getRoomTypeId());
    }

    /**
     * 通过主键删除数据
     *
     * @param roomTypeId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer roomTypeId) {
        return this.hotelRoomTypeMapper.deleteById(roomTypeId) > 0;
    }

    @Override
    public List<HotelRoomType> queryTheAll(){
        return this.hotelRoomTypeMapper.queryTheAll();
    }

}
